package org.glorylight.hacks.social.model;

import java.io.Serializable;
import java.util.Date;
import java.util.UUID;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.Type;

@Entity
@Table(name = "notification")
@NamedQueries({
	@NamedQuery(name = "notification-by-user", query = "from Notification a where a.notifyUser = :userId"),
	@NamedQuery(name = "notification-by-user-date", query = "from Notification a where a.notifyUser = :userId " +
				"AND (a.dateCreated BETWEEN :startDate AND :endDate)"),
	@NamedQuery(name = "notification-by-date", query = "from Notification a where a.dateCreated BETWEEN :startDate AND :endDate"),
	})
public class Notification implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -5360824323973645567L;

	@Id
	@Type(type = "uuid")
	@Column(length = 32)
	private UUID id;

	@Column(name = "notify_user", nullable = false, length = 50)
	private String notifyUser;
	
	@Column(name = "book_id")
	private UUID scrapBookId;
	
	@Column(name = "network_id")
	private UUID networkId;
	
	@Temporal(TemporalType.DATE)
	@Column(name = "date_created")
	private Date dateCreated;
	
	@Column(name = "is_notified", length=1)
	private int isNotified;
	
	@Column(name = "type", length=2)
	private int type;

	public Notification(UUID id, String notifyUser, UUID scrapBookId, UUID networkId, Date dateCreated, int type){
		this.notifyUser = notifyUser;
		this.scrapBookId = scrapBookId;
		this.dateCreated = dateCreated;
		this.networkId = networkId;
		this.isNotified = 0;
		this.type = type;
		this.id = id;
	}

	public Notification(){
	}
	
	public String getNotifyUser() {
		return notifyUser;
	}

	public void setNotifyUser(String notifyUser) {
		this.notifyUser = notifyUser;
	}

	public Date getDateCreated() {
		return dateCreated;
	}

	public void setDateCreated(Date dateCreated) {
		this.dateCreated = dateCreated;
	}

	public UUID getId() {
		return id;
	}
	
	public UUID getNetworkId() {
		return networkId;
	}

	public void setNetworkId(UUID networkId) {
		this.networkId = networkId;
	}

	public boolean isNotified() {
		return isNotified == 1 ? Boolean.TRUE : Boolean.FALSE;
	}

	public void setIsNotified(int isNotified) {
		this.isNotified = isNotified;
	}
	
	public int getIsNotified() {
		return isNotified;
	}

	public UUID getScrapBookId() {
		return scrapBookId;
	}

	public void setScrapBookId(UUID scrapBookId) {
		this.scrapBookId = scrapBookId;
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}
	
}
